package com.lmu.travel.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lmu.travel.dao.OrderDao;
import com.lmu.travel.entity.Order;
import com.lmu.travel.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author liuxuhuang
 * @className: OrderServiceImpl
 * @description: 订单service层接口实现类
 * @email liuxuhuang3970@qq.com
 * @date 2021/6/29 21:17
 * @version：1.0
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderDao, Order> implements OrderService {
    @Autowired
    private OrderDao orderDao;

    @Override
    public int insert(Order order) {
        order.setStatus("0");
        Date date = new Date();
        order.setCreatetime(date);
        order.setUpdatetime(date);
        int i = orderDao.insert(order);
        return i;
    }


    @Override
    public Order findByOrderId(String orderId) {
        return orderDao.findByOrderId(orderId);
    }

    @Override
    public int updateStatusSuccess(String orderId) {
        Order order = new Order();
        order.setOrderid(orderId);
        order.setStatus("1");
        Date updatetime = new Date();
        order.setUpdatetime(updatetime);
        order.setPaymenttime(updatetime);
        int i = orderDao.updateByOrderId(order);
        return i;
    }

    @Override
    public int updateStatusTimeOut(String orderId) {
        Order order = new Order();
        order.setOrderid(orderId);
        order.setStatus("2");
        Date updatetime = new Date();
        order.setUpdatetime(updatetime);
        order.setClosetime(updatetime);
        int i = orderDao.updateByOrderId(order);
        return i;
    }
}
